$(document).ready(function() {
	//数据上传
	/*$("#dataAdd-wizard").find(".validateClass").jqBootstrapValidation({
		preventSubmit: true,
		submitSuccess: function($form, event) {
			
			event.preventDefault();
		},
		filter: function() {
			return $(this).is(":visible");
		}
	});*/
	$("#dataAdd-wizard").submit(function(){
		if(isNaN($("#isWeight").val())||isNaN($("#isAge").val())||isNaN($("#isPhone").val())){
			toastr.error("联系电话、孩子出生时母亲年龄、孩子出生体重必须为数字", '系统提示：');
			return false;
		}else{
			$.ajax({
				url: "/Handler/DataHandler.ashx",
				type: "post",
				dataType: "json",
				data: {
					fun: "f_0001",
					dataHTML: tn.Base64.encode($("#dataHTML").html()),
					data: JSON.stringify($("#dataAdd-wizard").serializeObject()),
				},
				beforeSend: function() {
					//数据加载冻屏
					$('#freezeModal').modal({
						backdrop: 'static',
					});
				},
				success: function(msg) {
					//数据加载完毕解除冻屏
					$('#freezeModal').modal('hide');
					if (msg.r_code == "1") {
						toastr.success(msg.r_info, '系统提示：');
						/*//清空form表单
						$("#dataAdd-wizard").get(0).reset();
						//刷新页面
						setTimeout(function() {
							window.location.href = window.location.href;
						}, 1000);*/
					} else if (msg.r_code == "0") {
						toastr.error(msg.r_info, '错误提示：');
					}
				}
			});
			return false;
		};
	});
	$('#dataAdd-wizard input').iCheck({
		checkboxClass: 'icheckbox_square-green',
		radioClass: 'iradio_square-green'
	}).on('ifChanged', function(event) {
		var valSum1 = "",
			valSum2 = "",
			valSum3 = "",
			CheckBoxEle = $(this).parents("ul").find("li input"),
			inputEle = $(this).parents("ul");
		CheckBoxEle.each(function(n) {
			if ($(this).prop("checked")) { //判断是否选中
				//如果有val val1 2个选项
				if ($(this).attr("val") || $(this).attr("val1")) {
					valSum1 += ($(this).attr("val") + ",");
					valSum2 += ($(this).attr("val1") + ",");
				};
				//如果有value 选项
				if ($(this).attr("value")) {
					valSum3 += ($(this).attr("value") + ",")
				}
			};
		});
		//如果父级能找到ai || an
		if (inputEle.find(".ai").length !== 0 || inputEle.find(".an").length !== 0) {
									 //删除最后一个多余的逗号			
			inputEle.find(".ai").val(valSum1.substr(0,valSum1.length-1)); 
			inputEle.find(".an").val(valSum2.substr(0,valSum2.length-1));
		};
		//如果父级能找到icheckVal
		if (inputEle.find(".icheckVal").length !== 0) {
			inputEle.find(".icheckVal").val(valSum3.substr(0,valSum3.length-1))
		};
	});
	$("#dataAdd-wizard").formwizard({
		validationEnabled: true,
		focusFirstInput: true,
		disableUIStyles: true,
		textBack: "返回",
		textNext: "下一步",
		textSubmit: "提交",
		validationOptions : {
			rules: {
				Guest_Name: "required",
				/*password: "required",
				password2: {
					equalTo: "#password"
				},
				email: { required: true, email: true },
				eula: "required"*/
			},
			messages: {
				Guest_Name: "内容不能为空",
				/*password: "You must enter the password",
				password2: { equalTo: "Password don't match" },
				email: { required: "Please, enter your email", email: "请输入正确格式的电子邮件，例如name@domain.com" },
				eula: "You must accept the eula"
				required: "内容不能为空",
				remote: "请修正该字段",
				email: "请输入正确格式的电子邮件",
				url: "请输入合法的网址",
				date: "请输入合法的日期",
				dateISO: "请输入合法的日期 (ISO).",
				number: "请输入合法的数字",
				digits: "只能输入整数",
				creditcard: "请输入合法的信用卡号",
				equalTo: "请再次输入相同的值",
				accept: "请输入拥有合法后缀名的字符串",
				maxlength: jQuery.validator.format("请输入一个 长度最多是 {0} 的字符串"),
				minlength: jQuery.validator.format("请输入一个 长度最少是 {0} 的字符串"),
				rangelength: jQuery.validator.format("请输入 一个长度介于 {0} 和 {1} 之间的字符串"),
				range: jQuery.validator.format("请输入一个介于 {0} 和 {1} 之间的值"),
				max: jQuery.validator.format("请输入一个最大为{0} 的值"),
				min: jQuery.validator.format("请输入一个最小为{0} 的值")
				*/
			},
			errorClass: "help-inline",
			errorElement: "span",
			highlight:function(element, errorClass, validClass) {
				$(element).parents('.control-group').addClass('error');
			},
			unhighlight: function(element, errorClass, validClass) {
				$(element).parents('.control-group').removeClass('error');
			}
		}
	});
	$("#dataAdd-wizard .dateInput").datepicker({
		format: 'yyyy-mm-dd'
	});

    $("#dataHTML input").keyup(function(){
        $(this).attr("value",$(this).val());
    });
});